using System;
using Microsoft.SPOT;
using dotnetwarrior.NetMF.Game;
using Microsoft.SPOT.Presentation.Media;

namespace dotnetwarrior.NetMF.Game
{
  public static class Utility
  {
    private static Random _prng = new Random();

    public static Rect[] TileExtractor(int startX, int startY, int spriteWidth, int spriteHeight, int spriteCountX, int spriteCountY, int borderWidth)
    {
      Rect[] rects = new Rect[spriteCountX * spriteCountY];

      int i = 0;
      for (int y = 0; y < spriteCountY; y++)
      {
        for (int x = 0; x < spriteCountX; x++)
        {        
          rects[i].X = startX + (x * spriteWidth) + borderWidth + (borderWidth * x);
          rects[i].Y = startY + (y * spriteHeight) + borderWidth + (borderWidth * y);
          rects[i].Width = spriteWidth;
          rects[i].Height = spriteHeight;
          i++;
        }
      }

      return rects;
    }

    public static int GetRandomNumber(int maxValue)
    {
      return _prng.Next(maxValue);
    }

    public static void ClearBitmap(Bitmap bmp, Color color)
    {
      bmp.DrawRectangle(color, 1, 0, 0, bmp.Width, bmp.Height, 0, 0, color, 0, 0, color, 0, 0, Bitmap.OpacityOpaque);
    }

    public static void ClearBitmap(Bitmap bmp, int x, int y, int width, int height, Color color)
    {
      bmp.DrawRectangle(color, 1, x, y, width, height, 0, 0, color, 0, 0, color, 0, 0, Bitmap.OpacityOpaque);
    }
  }
}
